home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CreatingGames / GameCreators / TADS / library / numbered.t < prev   
Encoding:
Text File  |  1997-03-15  |  2.1 KB  |  71 lines

  1. /*
  2.  *  numbered_cleanup: function
  3.  *  This function is used as a fuse to delete objects created by the
  4.  *  "numberedObject" class in reponse to calls to its newNumbered
  5.  *  method. Whenever that method creates a new object, it sets up a fuse
  6.  *  call to this function to delete the object at the end of the turn in
  7.  *  which it created the object.
  8. */
  9. numbered_cleanup: function( obj )
  10. {
  11.   delete obj;
  12. }
  13.  
  14. /*
  15.  *  numberedObject: object
  16.  *  This class can be added to a class list for an object to allow it to
  17.  *  be used as a generic numbered object.  You can create a single object
  18.  *  with this class, and then the player can refer to that object with
  19.  *  any number.  For example, you can create a single "button" object
  20.  *  that the player can refer to with "button 100'' or "button 1000''
  21.  *  or any other number.  If you want to limit the range of acceptable
  22.  *  numbers, override the "num_is_valid" method so that it displays
  23.  *  an appropriate error message and returns "nil" for invalid numbers.
  24.  *  If you want to use a separate object to handle references to the object
  25.  *  with a plural ("look at buttons"), override "newNumberedPlural" to
  26.  *  return the object to handle these references; by default, the original
  27.  *  object is used to handle plurals.
  28. */
  29.  
  30. class numberedObject: object
  31.   adjective = '#'
  32.   anyvalue( n ) = { return n; }
  33.   clean_up = { delete self; }
  34.   newNumberedPlural( a, v ) = { return self; }
  35.   newNumbered( a, v, n ) =
  36.   {
  37.     local obj;
  38.  
  39.     if ( n = nil ) return self.newNumberedPlural( a, v );
  40.     if ( not self.num_is_valid( n ) ) return nil;
  41.     obj := new self;
  42.     obj.value := n;
  43.     setfuse( numbered_cleanup, 0, obj );
  44.     return obj;
  45.   }
  46.   num_is_valid( n ) =
  47.   {
  48.     if ( n = 0 )
  49.     {
  50.       "There aren't zero "; self.pluraldesc; " here! ";
  51.       return nil;
  52.     }
  53.     else if ( n > self.maxNum )
  54.     {
  55.       "There aren't that many "; self.pluraldesc; "! ";
  56.       return nil;
  57.     }
  58.     else
  59.    return true;
  60.   }
  61.   dobjGen( a, v, i, p ) =
  62.   {
  63.     if ( self.value = nil )
  64.     {
  65.       "You'll have to be more specific about which one you mean. ";
  66.       exit;
  67.     }
  68.   }
  69.   iobjGen( a, v, d, p ) = { self.dobjGen( a, v, d, p ); }
  70.   maxNum = 10
  71. ;